﻿using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;

/// <summary>
/// DBParameter 的摘要说明
/// </summary>
[DataContract(IsReference = true)]
[KnownType(typeof(DBParameter))]
public class DBParameter
{
    private OracleDbType oracleType;//参数类型          
    private string parameterName;//参数名          
    private int size;//参数大小          
    private object parameterValue;//参数值
    private ParameterDirection direction;  //类型描述


    /// <summary>
    /// 
    /// </summary> 
    
    public DBParameter()
    {

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="parameterName"></param>
    /// <param name="dbType"></param>
    /// <param name="size"></param>
    public DBParameter(string parameterName, OracleDbType dbType, int size)
    {
        if (parameterName != null)
        {
            this.parameterName = parameterName.Trim();
        }
        this.oracleType = dbType;
        this.size = size;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="parameterName"></param>
    /// <param name="dbType"></param>
    /// <param name="size"></param>
    /// <param name="value"></param>
    public DBParameter(string parameterName, OracleDbType dbType, int size, object value)
    {
        if (parameterName != null)
        {
            this.parameterName = parameterName.Trim();
        }
        this.oracleType = dbType;
        this.size = size;
        this.parameterValue = value;
    }

    /// <summary>
    /// 
    /// </summary>
    [DataMember]
    public OracleDbType DBType
    {
        get
        {
            return oracleType;
        }
        set
        {
            this.oracleType = value;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    [DataMember]
    public string ParameterName
    {
        get
        {
            return this.parameterName;
        }
        set
        {
            if (value != null)
            {
                this.parameterName = value;
            }
            else
            {
                this.parameterName = null;
            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    [DataMember]
    public int Size
    {
        get
        {
            return this.size;
        }
        set
        {
            this.size = value;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    [DataMember]
    public object Value
    {
        get
        {
            return parameterValue;
        }
        set
        {
            this.parameterValue = value;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    [DataMember]
    public ParameterDirection Direction
    {
        get { return direction; }
        set { direction = value; }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public override bool Equals(object obj)
    {
        if (obj == null || obj.GetType() != this.GetType())
        {
            return false;
        }
        DBParameter p = (DBParameter)obj;
        return ((this.oracleType == p.oracleType) && (string.Compare(this.parameterName, p.parameterName, true, System.Globalization.CultureInfo.CurrentCulture) == 0) && (this.parameterValue.GetHashCode() == p.parameterValue.GetHashCode()) && (this.size == p.size));
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public override int GetHashCode()
    {
        return this.oracleType.GetHashCode() ^ this.parameterName.GetHashCode() ^ this.size.GetHashCode() ^ this.parameterValue.GetHashCode();
    }
}